The invention relates generally to graphics processing apparatus and methods and more particularly to graphics processing apparatus and methods that employ programmable shaders to produce pixels for display on a display.
Graphics processing circuits, such as graphics processors that are integrated on an integrated circuit, or are part of a larger system incorporated on an integrated circuit or multiple integrated circuits, are known to employ programmable shader hardware to produce pixels by among other things, retrieving texture information from a texture memory or texture cache and applying the texture to a pixel(s) that make up a portion of an object to give the object a particular three dimensional or two dimensional look. The object may be displayed on a display device such as a display screen or piece of paper printed by a printer, or any other output. For example, devices, such as cell phones, laptop computers, desktop computers, cable interface devices, printers, or any other suitable devices may employ graphics processing circuitry in the form of a graphics processing unit (GPU) or other structure and may also include a processor, such as a host processor, which executes a 3D application such as a 3D game or any other suitable application. A driver application also executing on the host processor includes a portion thereof that acts as a compiler that compiles instructions from the application into a format suitable for a programmable hardware pixel shader in the graphics processing circuitry to generate appropriate pixel information for display. In addition, shader code is a block of shader instructions for a given pixel. Shader code is known to include for some types of operations, conditional statements which is a block of instructions which, for example, may include an IF_THEN statement. For example, the IF portion of the IF_THEN statement defines a condition that must be met in order for the body of the THEN portion of the conditional statement to be carried out. As known in the art, mip map lookups typically require a determination of which mip map level (texture granularity level) to use to determine which texture address to retrieve for a given pixel. Typically, in order for a proper mip map selection to be made, the pixel shader needs valid neighboring pixel information since a mip map level is determined based on a plurality of pixels and not just one pixel. If a conditional statement (e.g. the body) requires a texture fetch, and a neighboring pixel does not meet the condition, an improper mip map level could result.
Stated another way, to compute a final color of a pixel, the pixel shader needs to evaluate neighboring pixels to determine an appropriate mip map level to do proper texture fetching. For example, conditional statements such as IF_THEN statements have a block of instructions therein that may require a texture fetch for the pixel. However, if the texture fetch has to be done, the proper mip map level must be known and the mip map level is based on the texture coordinate values of neighboring pixels. Known techniques require the shader code for each pixel to execute every time in order for a texture fetch to occur and the graphics processing system is not optimized.
For example, referring to FIG. 1, an object 100, such as a rectangle formed by four vertices, will be assumed to be a portion of a ball that will be displayed on a display device. In this example, a light source in the frame to be displayed creates a specular region 102 on the ball and is located in this example in the object 100. A specular region as known in the art may be, for example, the white portion of the object that is displayed to show that the portion of the ball is shiny and it is the reflection of the light source. Various 2×2 pixel regions (“quads”) are also shown as regions 104, 106, 108 and 1110. As shown, each 2×2 pixel region may require a texture to be applied to each of the pixels in the 2×2 pixel region. In this example, the 2×2 pixel region 104 has all of its four pixels in the specular region 102 of the object 100. Similarly, the 2×2 pixel region 110 has all of its pixels in a non-specular region of the object 100. In contrast, each of 2×2 pixel regions 106 and 108 include one or more pixels that are in the specular region 102 and one or more pixels that are outside of the specular region 102 (in a non-specular region).
It would be desirable to be able to conditionally execute shader code for only a subset of pixels, based on dynamic considerations such as executing shader code on only the subset of pixels that require the calculation of a specular term, such as the pixels in the 2×2 pixel region 104, that would reflect specularly towards the eye point. However, a problem is that if the condition, such as the pixels must specularly reflect, mip mapped texture lookups are required and mip map selection hardware requires valid neighboring pixel information, even for those pixels that would fail the condition test, such as pixels 112 and 114 that are outside of the specular region 102 and do not specularly reflect. However, the 2×2 pixel regions 108 and 106 include pixels that would require calculation of a specular term since some of these pixels do lie in the specular region 102.
One solution has been to calculate the mip map selection information unconditionally, and then only allow conditional texture fetches of the type that use this previously (unconditionally) calculated mip map selection information. Such solutions only execute the shader code for those pixels that do not rely on neighboring information on a conditional basis. However, in many cases, a large part of the calculation must be done for all pixels, rather than for only a small percentage of pixels, resulting in reduced system performance. Current systems may require the calculation of the texture address all of the time for all pixels and then perform texture fetches only if the pixels are within the area of concern. These additional calculations can result in unnecessary use of scarce resources, particularly when a complex 3D imaging application or applications are required to execute on a device.
Another solution is for a compiler to recognize the undesirability of the conditional texture fetch and move the texture fetch inside the conditional statement on its own and allocate registers so as to assure that the program visible state is not overwritten. The compiler in addition utilizes programmable shader hardware mechanisms that execute whenever a pixel of a 2×2 quad is active. However, the compiler may not perform an optimal job of rearranging texture fetches and may not result in optimum code for the shader.
Accordingly, a need exists to overcome one or more of the above problems.